package com.didd.core.constant.enums;


import com.didd.core.dict.core.DictEnumInterface;

/**
 * 通用删除枚举
 *
 * @author diddd
 * @since 2019/12/11
 */
public enum DeleteEnum implements DictEnumInterface {

    /**
     * 正常
     */
    NORMAL("0", "正常"),

    /**
     * 已删除
     */
    DELETED("1", "已删除"),

    /**
     * 未知
     */
    UNKNOWN("-1", "未知");

    private final String code;

    private final String name;

    DeleteEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public String getCode() {
        return code;
    }

    public Integer getCodeValue() {
        return Integer.valueOf(code);
    }

    @Override
    public String getName() {
        return name;
    }

    public static DeleteEnum getEnum(String code) {
        for (DeleteEnum item : DeleteEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return UNKNOWN;
    }

    public static DeleteEnum getEnum(Integer code) {
        for (DeleteEnum item : DeleteEnum.values()) {
            if (item.getCode().equals(String.valueOf(code))) {
                return item;
            }
        }
        return UNKNOWN;
    }

    public static String getName(String code) {
        DeleteEnum deleteEnum = DeleteEnum.getEnum(code);
        return deleteEnum.getName();
    }

    public static String getName(Integer code) {
        DeleteEnum deleteEnum = DeleteEnum.getEnum(code);
        return deleteEnum.getName();
    }
}
